<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport"
    content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no">
  <title>订单结算</title>
  <!-- HTML5 shim 和 Respond.js 是为了让 IE8 支持 HTML5 元素和媒体查询（media queries）功能 -->
  <!--[if lt IE 9]>
	      <script src="js/html5shiv.min.js"></script>
	      <script src="js/respond.min.js"></script>
      <![endif]-->
  <style>
    html {
      font-size: 62.5%;
    }

    body {
      font-size: 1.4rem;
      color: #333;
    }

    .red {
      color: red;
    }

    p {
      font-size: 1.4rem;
    }

    .box {
      text-align: center;
      margin-top: 3rem;
    }

    h1,
    h2,
    h3 {
      font-weight: normal;
    }

    h1,
    p,
    h2,
    div {
      font-size: 1.4rem;
    }

    .price {
      font-size: 3.6rem;
      margin: 1.5rem 0;
    }

    .wait {
      margin-bottom: 1.5rem;
    }

    .time-box {
      clear: both;
      height: auto;
      overflow: hidden;
      margin-bottom: 3rem;
    }

    .time-minute,
    .time-icon,
    .time-second {
      display: inline-block;
      vertical-align: middle;
      margin-bottom: 2rem;
    }

    .time-icon {
      padding: 0 2rem;
    }

    .time-minute span,
    .time-icon span,
    .time-second span {
      font-size: 2.6rem;
    }

    .time-minute div,
    .time-icon div,
    .time-second div {
      margin-top: 0.5rem;
    }

    h2 {
      color: red;
    }

    h3 {
      font-size: 1.2rem;
      margin-top: 3rem;
    }
  </style>
</head>

<body>
  <div id="app">
    <div class="box">
      <h1 class="red">请耐心等待匹配成功</h1>
      <p class="price">￥{{money}}</p>
      <div class="wait">订单匹配中，请稍后......</div>
      <div class="time-box">
        <div class="time-minute">
          <span>00</span>
          <div>分</div>
        </div>
        <div class="time-icon">
          <span>:</span>
          <div>&nbsp;</div>
        </div>
        <div class="time-second">
          <span>{{time}}</span>
          <div>秒</div>
        </div>
      </div>
      <h2>匹配到订单后务必在2分钟内完成付款</h2>
      <h2>若超时付款，资金无法追回</h2>
      <h2>此订单仅限缴费一次，请勿重复付款</h2>
      <h3>
        订单号：{{orderNo}}
      </h3>
    </div>
  </div>
  <script src="js/axios.min.js" type="text/javascript" charset="utf-8"></script>
  <script src="js/vue.js" type="text/javascript" charset="utf-8"></script>
  <script type="text/javascript">
    //获取导航地址参数的方法
    function getUrl(name) {
      var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
      var reg_rewrite = new RegExp("(^|/)" + name + "/([^/]*)(/|$)", "i");
      var r = window.location.search.substr(1).match(reg);
      var q = window.location.pathname.substr(1).match(reg_rewrite);
      if (r != null) {
        return unescape(r[2]);
      } else if (q != null) {
        return unescape(q[2]);
      } else {
        return null;
      }
    }
    var app = new Vue({
      el: "#app",
      data: {
        time: 120,
        timer: null,
        merchantId: '',//string	商户编号
        payType: '',//string	支付方式(wechat,alipay)
        notifyUrl: '',//string	通知地址
        money: '',//string	支付金额
        orderNo: '',//string	商户订单号
        sign: '',
        payUrl: ''// 接口地址
      },
      created() {
        let that = this
        that.payUrl = getUrl('payUrl')
        that.merchantId = getUrl('merchantId')
        that.payType = getUrl('payType')
        that.notifyUrl = getUrl('notifyUrl')
        that.money = getUrl('money')
        that.orderNo = getUrl('orderNo')
        that.sign = getUrl('sign')
        that.timer2 = setInterval(() => {
          if (that.time > 0) {
            that.time--
          }
        }, 1000)
        that.getResult()
      },
      beforeDestory() {
        let that = this
        setTimeout(that.timer)
        that.timer = null
        setInterval(that.timer2)
        that.timer2 = null
      },
      methods: {
        getResult() {
          let that = this
          that.timer = setTimeout(() => {
            if (that.time > 0) {
              axios({
                method: 'post',
                url: 'http://211.99.100.196:18002/telcompay/api/telcompayorder/fetchOrder',
                data: {
                  payUrl: this.payUrl,
                  merchantId: this.merchantId,
                  payType: this.payType,
                  notifyUrl: this.notifyUrl,
                  money: this.money,
                  orderNo: this.orderNo,
                  sign: this.sign,
                }
              }).then(res => {
                if (res.data && res.data.code === 200 && res.data.data) {
                  window.self.location = res.data.data;
                  clearTimeout(that.timer)
                  that.timer = null
                } else {
                  that.getResult()
                }
              })
            } else {
              clearTimeout(that.timer)
              that.timer = null
            }
          }, 1000)
        },
      }
    })
  </script>

</body>

</html>
